package top.mengchaob.deploy.util;

import com.jcraft.jsch.Channel;
import com.jcraft.jsch.JSchException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @title：
 * @author: mengchaob
 * @date: 2021年04月27日 13:26
 * @description:
 */
public class CloseChannel {
    private static Logger logger = LoggerFactory.getLogger(CloseChannel.class);
    public static void close(Channel channel){
        if(channel==null){
            CloseChannel.logger.debug("channel 为空！");
            return;
        }
        channel.disconnect();
        CloseChannel.logger.debug("channel 已经关闭");
        try {
            if(channel.getSession()!=null){
                channel.getSession().disconnect();
                CloseChannel.logger.debug("session 已经关闭");
            }else {
                CloseChannel.logger.debug("session 为空，不需要关闭！");
            }
        } catch (JSchException e) {
            e.printStackTrace();
        }
    }
}
